package com.ourteam.product.ui.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.ourteam.product.ui.dao.IProductUIActionDAO;
import com.ourteam.product.ui.dao.IProductUIActionGroupDAO;
import com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO;
import com.ourteam.product.ui.dao.IProductUIFormDAO;
import com.ourteam.product.ui.dao.IProductUIFormFieldDAO;
import com.ourteam.product.ui.dao.IProductUIFormLayoutDataDAO;
import com.ourteam.product.ui.dao.IProductUIImageDAO;
import com.ourteam.product.ui.dao.IProductUIListDAO;
import com.ourteam.product.ui.dao.IProductUIListOptionDAO;
import com.ourteam.product.ui.dao.IProductUITabDAO;
import com.ourteam.product.ui.dao.IProductUITabItemDAO;
import com.ourteam.product.ui.dao.IProductUITableColumnDAO;
import com.ourteam.product.ui.dao.IProductUITableDAO;
import com.ourteam.product.ui.dao.IProductUITreeDAO;
import com.ourteam.product.ui.dao.IProductUITreeNodeBuilderDAO;
import com.ourteam.product.ui.dao.IProductUITreeNodeDAO;
import com.ourteam.product.ui.dao.IProductUITreeRootNodeDAO;
import com.ourteam.product.ui.dao.ProductUIAction;
import com.ourteam.product.ui.dao.ProductUIActionDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIActionGroup;
import com.ourteam.product.ui.dao.ProductUIActionGroupDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIActionGroupRelate;
import com.ourteam.product.ui.dao.ProductUIActionGroupRelateDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIDomain;
import com.ourteam.product.ui.dao.ProductUIDomainDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIForm;
import com.ourteam.product.ui.dao.ProductUIFormDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIFormField;
import com.ourteam.product.ui.dao.ProductUIFormFieldDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIFormFieldType;
import com.ourteam.product.ui.dao.ProductUIFormFieldTypeDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIFormLayoutData;
import com.ourteam.product.ui.dao.ProductUIFormLayoutDataDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIImage;
import com.ourteam.product.ui.dao.ProductUIImageDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIList;
import com.ourteam.product.ui.dao.ProductUIListDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIListOption;
import com.ourteam.product.ui.dao.ProductUIListOptionDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIPage;
import com.ourteam.product.ui.dao.ProductUIPageDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIPageParam;
import com.ourteam.product.ui.dao.ProductUIPageParamDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIPageTemplate;
import com.ourteam.product.ui.dao.ProductUIPageTemplateDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUIPageTemplateParam;
import com.ourteam.product.ui.dao.ProductUIPageTemplateParamDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITab;
import com.ourteam.product.ui.dao.ProductUITabDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITabItem;
import com.ourteam.product.ui.dao.ProductUITabItemDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITable;
import com.ourteam.product.ui.dao.ProductUITableColumn;
import com.ourteam.product.ui.dao.ProductUITableColumnDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITableColumnIcon;
import com.ourteam.product.ui.dao.ProductUITableColumnIconDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITableDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITree;
import com.ourteam.product.ui.dao.ProductUITreeDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITreeNode;
import com.ourteam.product.ui.dao.ProductUITreeNodeBuilder;
import com.ourteam.product.ui.dao.ProductUITreeNodeBuilderDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITreeNodeDAOQueryBean;
import com.ourteam.product.ui.dao.ProductUITreeRootNode;
import com.ourteam.product.ui.dao.ProductUITreeRootNodeDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIActionBean;
import com.ourteam.product.ui.domain.ProductUIActionGroupBean;
import com.ourteam.product.ui.domain.ProductUIActionGroupRelateBean;
import com.ourteam.product.ui.domain.ProductUIDomainBean;
import com.ourteam.product.ui.domain.ProductUIFormBean;
import com.ourteam.product.ui.domain.ProductUIFormFieldBean;
import com.ourteam.product.ui.domain.ProductUIFormFieldTypeBean;
import com.ourteam.product.ui.domain.ProductUIFormLayoutDataBean;
import com.ourteam.product.ui.domain.ProductUIImageBean;
import com.ourteam.product.ui.domain.ProductUIListBean;
import com.ourteam.product.ui.domain.ProductUIListOptionBean;
import com.ourteam.product.ui.domain.ProductUIPageBean;
import com.ourteam.product.ui.domain.ProductUIPageParamBean;
import com.ourteam.product.ui.domain.ProductUIPageTemplateBean;
import com.ourteam.product.ui.domain.ProductUIPageTemplateParamBean;
import com.ourteam.product.ui.domain.ProductUITabBean;
import com.ourteam.product.ui.domain.ProductUITabItemBean;
import com.ourteam.product.ui.domain.ProductUITableBean;
import com.ourteam.product.ui.domain.ProductUITableColumnBean;
import com.ourteam.product.ui.domain.ProductUITableColumnIconBean;
import com.ourteam.product.ui.domain.ProductUITreeBean;
import com.ourteam.product.ui.domain.ProductUITreeNodeBean;
import com.ourteam.product.ui.domain.ProductUITreeNodeBuilderBean;

/**
 *
 * Template Name : 业务服务实现 Template Version : 1 Template Last Modfiy Date : Thu
 * Nov 23 10:43:58 CST 2017 Auto Generate Date : 2018-01-12 13:33:30
 *
 */
public class ProductUIServiceImpl extends AbstractProductUIService {
	/**
	 * 
	 * 
	 * @param aProductUIDomain
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected void doAddNewProductUIDomain(final com.ourteam.product.ui.domain.ProductUIDomainBean aProductUIDomain)
			throws Exception {

		this.productUIDomainDao.insert(aProductUIDomain.convertToProductUIDomain());
	}

	/**
	 * 
	 * 
	 * @param aProductUIDomain
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected void doModifyProductUIDomain(final com.ourteam.product.ui.domain.ProductUIDomainBean aProductUIDomain)
			throws Exception {

		this.productUIDomainDao.update(aProductUIDomain.convertToProductUIDomain());
	}

	/**
	 * 
	 * 
	 * @param aProductUIDomainIds
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected void doDeleteProductUIDomains(final long[] aProductUIDomainIds) throws Exception {

		ProductUIDomainDAOQueryBean queryBean = new ProductUIDomainDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIDomainIds);

		this.productUIDomainDao.delete(queryBean);

	}

	/**
	 * 
	 * 
	 * @param aProductUIDomainId
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected com.ourteam.product.ui.domain.ProductUIDomainBean doGetProductUIDomainById(final long aProductUIDomainId)
			throws Exception {

		ProductUIDomain productUIDomain = this.productUIDomainDao.findById(aProductUIDomainId);

		return productUIDomain != null ? new ProductUIDomainBean(productUIDomain) : null;
	}

	/**
	 * 
	 * 
	 * @param queryBean
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected com.ourteam.product.ui.domain.ProductUIDomainBean[] doQueryProductUIDomains(
			final com.ourteam.product.ui.dao.ProductUIDomainDAOQueryBean queryBean) throws Exception {

		return ProductUIDomainBean.toArray(this.productUIDomainDao.query(queryBean));
	}

	/**
	 * 
	 * 
	 * @param queryBean
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected int doQueryProductUIDomainCount(final com.ourteam.product.ui.dao.ProductUIDomainDAOQueryBean queryBean)
			throws Exception {

		return this.productUIDomainDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIAction(ProductUIActionBean aProductUIAction) throws Exception {

		if (aProductUIAction.getParentId() != 0) {
			ProductUIActionDAOQueryBean queryBean = new ProductUIActionDAOQueryBean();
			queryBean.createCriteria().andParentIdEqualTo(aProductUIAction.getParentId());

			int count = this.productUIActionDao.queryCount(queryBean);

			aProductUIAction.setSortIndex(count + 1);
		}

		this.productUIActionDao.insert(aProductUIAction.convertToProductUIAction());

	}

	@Override
	protected void doModifyProductUIAction(ProductUIActionBean aProductUIAction) throws Exception {

		if (aProductUIAction.getParentId() != 0) {
			ProductUIActionDAOQueryBean queryBean = new ProductUIActionDAOQueryBean();

			queryBean.setSortProperty(IProductUIActionDAO.SortIndex);

			queryBean.createCriteria().andParentIdEqualTo(aProductUIAction.getParentId());

			ProductUIAction[] subAction = this.productUIActionDao.query(queryBean);

			if (subAction[aProductUIAction.getSortIndex() - 1] != null
					&& subAction[aProductUIAction.getSortIndex() - 1].getId() != aProductUIAction.getId()) {
				for (int i = 0; i < subAction.length; i++) {
					if (subAction[i].getId() == aProductUIAction.getId()) {
						subAction[aProductUIAction.getSortIndex() - 1].setSortIndex(subAction[i].getSortIndex());
						this.productUIActionDao.update(subAction[aProductUIAction.getSortIndex() - 1]);
					}
				}
			}
			this.productUIActionDao.update(aProductUIAction.convertToProductUIAction());
		} else {
			this.productUIActionDao.update(aProductUIAction.convertToProductUIAction());
		}
	}

	@Override
	protected void doDeleteProductUIActions(long[] aProductUIActionIds) throws Exception {

		ProductUIActionDAOQueryBean parentQueryBean = new ProductUIActionDAOQueryBean();

		parentQueryBean.createCriteria().andIdIn(aProductUIActionIds);

		parentQueryBean.addParentIdSelectProperty("parentId");

		Map<String, Object>[] maps = this.productUIActionDao.querySelective(parentQueryBean);

		ProductUIActionDAOQueryBean queryBean = new ProductUIActionDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIActionIds);

		this.productUIActionDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {

			Map<String, Object> map = maps[i];

			if (MapUtils.getLongValue(map, "parentId") != 0) {

				queryBean.clear();

				queryBean.setSortProperty(IProductUIActionDAO.SortIndex);

				queryBean.createCriteria().andParentIdEqualTo(MapUtils.getLongValue(map, "parentId"));

				ProductUIAction[] subActions = this.productUIActionDao.query(queryBean);

				for (int j = 0; j < subActions.length; j++) {
					subActions[j].setSortIndex(j + 1);
				}

				this.productUIActionDao.batchUpdate(subActions);
			}

		}

	}

	@Override
	protected ProductUIActionBean doGetProductUIActionById(long aProductUIActionId) throws Exception {

		ProductUIAction productUIAction = this.productUIActionDao.findById(aProductUIActionId);

		return productUIAction != null ? new ProductUIActionBean(productUIAction) : null;
	}

	@Override
	protected ProductUIActionBean[] doQueryProductUIActions(ProductUIActionDAOQueryBean queryBean) throws Exception {

		return ProductUIActionBean.toArray(this.productUIActionDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIActionCount(ProductUIActionDAOQueryBean queryBean) throws Exception {

		return this.productUIActionDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIActionGroup(ProductUIActionGroupBean aProductUIActionGroup) throws Exception {

		this.productUIActionGroupDao.insert(aProductUIActionGroup.convertToProductUIActionGroup());

	}

	@Override
	protected void doModifyProductUIActionGroup(ProductUIActionGroupBean aProductUIActionGroup) throws Exception {

		this.productUIActionGroupDao.update(aProductUIActionGroup.convertToProductUIActionGroup());

	}

	@Override
	protected void doDeleteProductUIActionGroups(long[] aProductUIActionGroupIds) throws Exception {

		ProductUIActionGroupDAOQueryBean queryBean = new ProductUIActionGroupDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIActionGroupIds);

		this.productUIActionGroupDao.delete(queryBean);

		this.productUIActionGroupDao.deleteProductUIActionGroupRelate(queryBean);

	}

	@Override
	protected ProductUIActionGroupBean doGetProductUIActionGroupById(long aProductUIActionGroupId) throws Exception {

		ProductUIActionGroup actionGroup = this.productUIActionGroupDao.findById(aProductUIActionGroupId);

		return actionGroup != null ? new ProductUIActionGroupBean(actionGroup) : null;
	}

	@Override
	protected ProductUIActionGroupBean[] doQueryProductUIActionGroups(ProductUIActionGroupDAOQueryBean queryBean)
			throws Exception {

		return ProductUIActionGroupBean.toArray(this.productUIActionGroupDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIActionGroupCount(ProductUIActionGroupDAOQueryBean queryBean) throws Exception {

		return this.productUIActionGroupDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIActionGroupRelate(ProductUIActionGroupRelateBean aProductUIActionGroupRelate)
			throws Exception {

		ProductUIActionGroupRelateDAOQueryBean queryBean = new ProductUIActionGroupRelateDAOQueryBean();

		queryBean.createCriteria().andActionGroupIdEqualTo(aProductUIActionGroupRelate.getActionGroupId());

		int count = this.productUIActionGroupRelateDao.queryCount(queryBean);

		aProductUIActionGroupRelate.setSortIndex(count + 1);

		this.productUIActionGroupRelateDao.insert(aProductUIActionGroupRelate.convertToProductUIActionGroupRelate());

		this.productUIActionGroupDao
				.update(this.productUIActionGroupDao.findById(aProductUIActionGroupRelate.getActionGroupId()));

	}

	@Override
	protected void doModifyProductUIActionGroupRelate(ProductUIActionGroupRelateBean aProductUIActionGroupRelate)
			throws Exception {

		ProductUIActionGroupRelateDAOQueryBean queryBean = new ProductUIActionGroupRelateDAOQueryBean();

		queryBean.setSortProperty(IProductUIActionGroupRelateDAO.SortIndex);

		queryBean.createCriteria().andActionGroupIdEqualTo(aProductUIActionGroupRelate.getActionGroupId());

		ProductUIActionGroupRelate[] relates = this.productUIActionGroupRelateDao.query(queryBean);

		if (relates[aProductUIActionGroupRelate.getSortIndex() - 1] != null
				&& relates[aProductUIActionGroupRelate.getSortIndex() - 1].getId() != aProductUIActionGroupRelate
						.getId()) {
			for (int i = 0; i < relates.length; i++) {
				if (relates[i].getId() == aProductUIActionGroupRelate.getId()) {
					relates[aProductUIActionGroupRelate.getSortIndex() - 1].setSortIndex(relates[i].getSortIndex());
					this.productUIActionGroupRelateDao.update(relates[aProductUIActionGroupRelate.getSortIndex() - 1]);
				}
			}
		}

		this.productUIActionGroupRelateDao.update(aProductUIActionGroupRelate.convertToProductUIActionGroupRelate());

		ProductUIActionGroup productUIActionGroup = this.productUIActionGroupDao
				.findById(aProductUIActionGroupRelate.getActionGroupId());

		productUIActionGroup.setLastModifyTime(new Date());

		this.productUIActionGroupDao.update(productUIActionGroup);

	}

	@Override
	protected void doDeleteProductUIActionGroupRelates(long[] aProductUIActionGroupRelateIds) throws Exception {

		ProductUIActionGroupRelateDAOQueryBean queryBean = new ProductUIActionGroupRelateDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIActionGroupRelateIds);

		queryBean.addActionGroupIdSelectProperty("actionGroupId");

		Map<String, Object>[] maps = this.productUIActionGroupRelateDao.querySelective(queryBean);

		this.productUIActionGroupRelateDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {

			Map<String, Object> map = maps[i];

			ProductUIActionGroup actionGroup = new ProductUIActionGroup();

			actionGroup.setId(MapUtils.getLongValue(map, "actionGroupId"));

			actionGroup.setLastModifyTime(new Date());

			this.productUIActionGroupDao.update(actionGroup);

			queryBean.clear();

			queryBean.setSortProperty(IProductUIActionGroupRelateDAO.SortIndex);

			queryBean.createCriteria().andActionGroupIdEqualTo(MapUtils.getLongValue(map, "actionGroupId"));

			ProductUIActionGroupRelate[] relates = this.productUIActionGroupRelateDao.query(queryBean);

			for (int j = 0; j < relates.length; j++) {
				relates[j].setSortIndex(j + 1);
			}

			this.productUIActionGroupRelateDao.batchUpdate(relates);

		}

	}

	@Override
	protected ProductUIActionGroupRelateBean doGetProductUIActionGroupRelateById(long aProductUIActionGroupRelateId)
			throws Exception {

		ProductUIActionGroupRelate actionGroupRelate = this.productUIActionGroupRelateDao
				.findById(aProductUIActionGroupRelateId);

		return actionGroupRelate != null ? new ProductUIActionGroupRelateBean(actionGroupRelate) : null;
	}

	@Override
	protected ProductUIActionGroupRelateBean[] doQueryProductUIActionGroupRelates(
			ProductUIActionGroupRelateDAOQueryBean queryBean) throws Exception {

		return ProductUIActionGroupRelateBean.toArray(this.productUIActionGroupRelateDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIActionGroupRelateCount(ProductUIActionGroupRelateDAOQueryBean queryBean)
			throws Exception {
		return this.productUIActionGroupRelateDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIForm(ProductUIFormBean aProductUIForm) throws Exception {

		this.productUIFormDao.insert(aProductUIForm.convertToProductUIForm());

	}

	@Override
	protected void doModifyProductUIForm(ProductUIFormBean aProductUIForm) throws Exception {

		this.productUIFormDao.update(aProductUIForm.convertToProductUIForm());

	}

	@Override
	protected ProductUIFormBean doGetProductUIFormById(long aProductUIFormId) throws Exception {

		ProductUIForm productUIForm = this.productUIFormDao.findById(aProductUIFormId);

		return productUIForm != null ? new ProductUIFormBean(productUIForm) : null;
	}

	@Override
	protected void doDeleteProductUIForms(long[] aProductUIFormIds) throws Exception {

		ProductUIFormDAOQueryBean queryBean = new ProductUIFormDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIFormIds);

		this.productUIFormDao.delete(queryBean);

	}

	@Override
	protected ProductUIFormBean[] doQueryProductUIForms(ProductUIFormDAOQueryBean queryBean) throws Exception {

		return ProductUIFormBean.toArray(this.productUIFormDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIFormCount(ProductUIFormDAOQueryBean queryBean) throws Exception {

		return this.productUIFormDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIFormFieldType(ProductUIFormFieldTypeBean aProductUIFormFieldType) throws Exception {

		this.productUIFormFieldTypeDao.insert(aProductUIFormFieldType.convertToProductUIFormFieldType());

	}

	@Override
	protected void doModifyProductUIFormFieldType(ProductUIFormFieldTypeBean aProductUIFormFieldType) throws Exception {

		this.productUIFormFieldTypeDao.update(aProductUIFormFieldType.convertToProductUIFormFieldType());

	}

	@Override
	protected ProductUIFormFieldTypeBean doGetProductUIFormFieldTypeById(long aProductUIFormFieldTypeId)
			throws Exception {

		ProductUIFormFieldType fieldType = this.productUIFormFieldTypeDao.findById(aProductUIFormFieldTypeId);

		return fieldType != null ? new ProductUIFormFieldTypeBean(fieldType) : null;
	}

	@Override
	protected void doDeleteProductUIFormFieldTypes(long[] aProductUIFormFieldTypeIds) throws Exception {

		ProductUIFormFieldTypeDAOQueryBean queryBean = new ProductUIFormFieldTypeDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIFormFieldTypeIds);

		this.productUIFormFieldTypeDao.delete(queryBean);

	}

	@Override
	protected ProductUIFormFieldTypeBean[] doQueryProductUIFormFieldTypes(ProductUIFormFieldTypeDAOQueryBean queryBean)
			throws Exception {

		return ProductUIFormFieldTypeBean.toArray(this.productUIFormFieldTypeDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIFormFieldTypeCount(ProductUIFormFieldTypeDAOQueryBean queryBean) throws Exception {

		return this.productUIFormFieldTypeDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIFormField(ProductUIFormFieldBean aProductUIFormField) throws Exception {

		if(aProductUIFormField.getSortIndex() == 0) {
			ProductUIFormFieldDAOQueryBean queryBean = new ProductUIFormFieldDAOQueryBean();

			queryBean.createCriteria().andFormIdEqualTo(aProductUIFormField.getFormId())
					.andParentIdEqualTo(aProductUIFormField.getParentId());

			int count = this.productUIFormFieldDao.queryCount(queryBean);

			aProductUIFormField.setSortIndex(count + 1);
		}

		this.productUIFormFieldDao.insert(aProductUIFormField.convertToProductUIFormField());

		this.productUIFormDao.update(this.productUIFormDao.findById(aProductUIFormField.getFormId()));

	}

	@Override
	protected void doModifyProductUIFormField(ProductUIFormFieldBean aProductUIFormField) throws Exception {

		ProductUIFormFieldDAOQueryBean queryBean = new ProductUIFormFieldDAOQueryBean();

		queryBean.setSortProperty(IProductUIFormFieldDAO.SortIndex);

		queryBean.createCriteria().andFormIdEqualTo(aProductUIFormField.getFormId())
				.andParentIdEqualTo(aProductUIFormField.getParentId());

		ProductUIFormField[] fields = this.productUIFormFieldDao.query(queryBean);

		if (fields[aProductUIFormField.getSortIndex() - 1] != null
				&& fields[aProductUIFormField.getSortIndex() - 1].getId() != aProductUIFormField.getId()) {
			for (int i = 0; i < fields.length; i++) {
				if (fields[i].getId() == aProductUIFormField.getId()) {
					fields[aProductUIFormField.getSortIndex() - 1].setSortIndex(fields[i].getSortIndex());
					this.productUIFormFieldDao.update(fields[aProductUIFormField.getSortIndex() - 1]);
				}
			}
		}

		this.productUIFormFieldDao.update(aProductUIFormField.convertToProductUIFormField());

		ProductUIForm uiForm = this.productUIFormDao.findById(aProductUIFormField.getFormId());

		uiForm.setLastModifyTime(new Date());

		this.productUIFormDao.update(uiForm);
	}

	@Override
	protected void doDeleteProductUIFormFields(long[] aProductUIFormFieldIds) throws Exception {

		ProductUIFormFieldDAOQueryBean queryBean = new ProductUIFormFieldDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIFormFieldIds);

		queryBean.addFormIdSelectProperty("formId");

		queryBean.addParentIdSelectProperty("parentId");

		Map<String, Object>[] maps = this.productUIFormFieldDao.querySelective(queryBean);

		this.productUIFormFieldDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {

			Map<String, Object> map = maps[i];

			ProductUIForm form = new ProductUIForm();

			form.setId(MapUtils.getLongValue(map, "formId"));

			form.setLastModifyTime(new Date());

			this.productUIFormDao.update(form);

			queryBean.clear();

			queryBean.setSortProperty(IProductUIFormFieldDAO.SortIndex);

			queryBean.createCriteria().andFormIdEqualTo(MapUtils.getLongValue(map, "formId"))
					.andParentIdEqualTo(MapUtils.getLongValue(map, "parentId"));

			ProductUIFormField[] fields = this.productUIFormFieldDao.query(queryBean);

			for (int j = 0; j < fields.length; j++) {
				fields[j].setSortIndex(j + 1);
			}

			this.productUIFormFieldDao.batchUpdate(fields);
		}

	}

	@Override
	protected ProductUIFormFieldBean doGetProductUIFormFieldById(long aProductUIFormFieldId) throws Exception {

		ProductUIFormField formField = this.productUIFormFieldDao.findById(aProductUIFormFieldId);

		return formField != null ? new ProductUIFormFieldBean(formField) : null;
	}

	@Override
	protected ProductUIFormFieldBean[] doQueryProductUIFormFields(ProductUIFormFieldDAOQueryBean queryBean)
			throws Exception {

		return ProductUIFormFieldBean.toArray(this.productUIFormFieldDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIFormFieldCount(ProductUIFormFieldDAOQueryBean queryBean) throws Exception {

		return this.productUIFormFieldDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIFormLayoutData(ProductUIFormLayoutDataBean aProductUIFormLayoutData)
			throws Exception {

		this.productUIFormLayoutDataDao.insert(aProductUIFormLayoutData.convertToProductUIFormLayoutData());

		this.productUIFormDao.update(this.productUIFormDao
				.findById(this.productUIFormFieldDao.findById(aProductUIFormLayoutData.getFormFieldId()).getFormId()));

	}

	@Override
	protected void doModifyProductUIFormLayoutData(ProductUIFormLayoutDataBean aProductUIFormLayoutData)
			throws Exception {

		this.productUIFormLayoutDataDao.update(aProductUIFormLayoutData.convertToProductUIFormLayoutData());

		this.productUIFormDao.update(this.productUIFormDao
				.findById(this.productUIFormFieldDao.findById(aProductUIFormLayoutData.getFormFieldId()).getFormId()));
	}

	@Override
	protected ProductUIFormLayoutDataBean doGetProductUIFormLayoutDataByID(long aProductUIFormLayoutDataId)
			throws Exception {

		ProductUIFormLayoutData formLayoutData = this.productUIFormLayoutDataDao.findById(aProductUIFormLayoutDataId);

		return formLayoutData != null ? new ProductUIFormLayoutDataBean(formLayoutData) : null;
	}

	@Override
	protected void doDeleteProductUIFormLayoutDatas(long[] aProductUIFormLayoutDataIds) throws Exception {

		ProductUIFormLayoutDataDAOQueryBean queryBean = new ProductUIFormLayoutDataDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIFormLayoutDataIds);

		queryBean.addFormFieldIdSelectProperty();

		Map<String, Object>[] maps = this.productUIFormLayoutDataDao.querySelective(queryBean);

		this.productUIFormLayoutDataDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {
			Map<String, Object> map = maps[i];
			this.productUIFormDao.update(this.productUIFormDao.findById(this.productUIFormFieldDao
					.findById(MapUtils.getLongValue(map, IProductUIFormLayoutDataDAO.DataProperty.FormFieldId))
					.getFormId()));
		}

	}

	@Override
	protected ProductUIFormLayoutDataBean[] doQueryProductUIFormLayoutDatas(
			ProductUIFormLayoutDataDAOQueryBean queryBean) throws Exception {

		return ProductUIFormLayoutDataBean.toArray(this.productUIFormLayoutDataDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIFormLayoutDataCount(ProductUIFormLayoutDataDAOQueryBean queryBean) throws Exception {

		return this.productUIFormLayoutDataDao.queryCount(queryBean);
	}

	@Override
	protected ProductUIFormLayoutDataBean[] doGetProductUIFormFieldLayoutDatas(long aFormFieldId) throws Exception {

		ProductUIFormLayoutDataDAOQueryBean queryBean = new ProductUIFormLayoutDataDAOQueryBean();

		queryBean.createCriteria().andFormFieldIdEqualTo(aFormFieldId);

		return queryProductUIFormLayoutDatas(queryBean);
	}

	@Override
	protected void doSetProductUIFormFieldLayoutDatas(long aFormFieldId,
			ProductUIFormLayoutDataBean[] aProductUIFormLayoutDatas) throws Exception {

		ProductUIFormLayoutData[] formLayoutDatas = new ProductUIFormLayoutData[aProductUIFormLayoutDatas.length];

		for (int i = 0; i < formLayoutDatas.length; i++) {
			formLayoutDatas[i] = aProductUIFormLayoutDatas[i].convertToProductUIFormLayoutData();
			formLayoutDatas[i].setFormFieldId(aFormFieldId);
		}

		ProductUIFormLayoutDataDAOQueryBean queryBean = new ProductUIFormLayoutDataDAOQueryBean();

		queryBean.createCriteria().andFormFieldIdEqualTo(aFormFieldId);

		this.productUIFormLayoutDataDao.synchronize(formLayoutDatas, queryBean);

	}

	@Override
	protected void doAddNewProductUITable(ProductUITableBean aProductUITable) throws Exception {

		this.productUITableDao.insert(aProductUITable.convertToProductUITable());

	}

	@Override
	protected void doModifyProductUITable(ProductUITableBean aProductUITable) throws Exception {

		this.productUITableDao.update(aProductUITable.convertToProductUITable());

	}

	@Override
	protected void doDeleteProductUITables(long[] aProductUITableIds) throws Exception {

		ProductUITableDAOQueryBean queryBean = new ProductUITableDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITableIds);

		this.productUITableDao.delete(queryBean);

	}

	@Override
	protected ProductUITableBean doGetProductUITableById(long aProductUITableId) throws Exception {

		ProductUITable productUITable = this.productUITableDao.findById(aProductUITableId);

		return productUITable != null ? new ProductUITableBean(productUITable) : null;
	}

	@Override
	protected ProductUITableBean[] doQueryProductUITables(ProductUITableDAOQueryBean queryBean) throws Exception {

		return ProductUITableBean.toArray(this.productUITableDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITableCount(ProductUITableDAOQueryBean queryBean) throws Exception {

		return this.productUITableDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUITableColumn(ProductUITableColumnBean aProductUITableColumn) throws Exception {

		if (aProductUITableColumn.getSortIndex() == 0) {
			ProductUITableColumnDAOQueryBean queryBean = new ProductUITableColumnDAOQueryBean();

			queryBean.createCriteria().andTableIdEqualTo(aProductUITableColumn.getTableId());

			int count = this.productUITableColumnDao.queryCount(queryBean);

			aProductUITableColumn.setSortIndex(count + 1);
		}

		this.productUITableColumnDao.insert(aProductUITableColumn.convertToProductUITableColumn());

		this.productUITableDao.update(this.productUITableDao.findById(aProductUITableColumn.getTableId()));

	}

	@Override
	protected void doModifyProductUITableColumn(ProductUITableColumnBean aProductUITableColumn) throws Exception {

		ProductUITableColumnDAOQueryBean queryBean = new ProductUITableColumnDAOQueryBean();

		queryBean.setSortProperty(IProductUITableColumnDAO.SortIndex);

		queryBean.createCriteria().andTableIdEqualTo(aProductUITableColumn.getTableId());

		ProductUITableColumn[] columns = this.productUITableColumnDao.query(queryBean);

		if (columns[aProductUITableColumn.getSortIndex() - 1] != null
				&& columns[aProductUITableColumn.getSortIndex() - 1].getId() != aProductUITableColumn.getId()) {
			for (int i = 0; i < columns.length; i++) {
				if (columns[i].getId() == aProductUITableColumn.getId()) {
					columns[aProductUITableColumn.getSortIndex() - 1].setSortIndex(columns[i].getSortIndex());
					this.productUITableColumnDao.update(columns[aProductUITableColumn.getSortIndex() - 1]);
				}
			}
		}

		this.productUITableColumnDao.update(aProductUITableColumn.convertToProductUITableColumn());

		this.productUITableDao.update(this.productUITableDao.findById(aProductUITableColumn.getTableId()));

	}

	@Override
	protected ProductUITableColumnBean doGetProductUITableColumnById(long aProductUITableColumnId) throws Exception {

		ProductUITableColumn tableColumn = this.productUITableColumnDao.findById(aProductUITableColumnId);

		return tableColumn != null ? new ProductUITableColumnBean(tableColumn) : null;
	}

	@Override
	protected void doDeleteProductUITableColumns(long[] aProductUITableColumnIds) throws Exception {

		ProductUITableColumnDAOQueryBean queryBean = new ProductUITableColumnDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITableColumnIds);

		queryBean.addTableIdSelectProperty("tableId");

		Map<String, Object>[] maps = this.productUITableColumnDao.querySelective(queryBean);

		this.productUITableColumnDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {

			Map<String, Object> map = maps[i];

			ProductUITable uiTable = new ProductUITable();

			uiTable.setId(MapUtils.getLongValue(map, "tableId"));

			uiTable.setLastModifyTime(new Date());

			this.productUITableDao.update(uiTable);

			queryBean.clear();

			queryBean.setSortProperty(IProductUITableColumnDAO.SortIndex);

			queryBean.createCriteria().andTableIdEqualTo(MapUtils.getLongValue(map, "tableId"));

			ProductUITableColumn[] columns = this.productUITableColumnDao.query(queryBean);

			for (int j = 0; j < columns.length; j++) {
				columns[j].setSortIndex(j + 1);
			}

			this.productUITableColumnDao.batchUpdate(columns);

		}

	}

	@Override
	protected ProductUITableColumnBean[] doQueryProductUITableColumns(ProductUITableColumnDAOQueryBean queryBean)
			throws Exception {

		return ProductUITableColumnBean.toArray(this.productUITableColumnDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITableColumnCount(ProductUITableColumnDAOQueryBean queryBean) throws Exception {

		return this.productUITableColumnDao.queryCount(queryBean);
	}

	@Override
	protected ProductUITableColumnBean[] doGetProductUITableColumns(long aProductUITableId) throws Exception {

		ProductUITableColumnDAOQueryBean queryBean = new ProductUITableColumnDAOQueryBean();

		queryBean.createCriteria().andTableIdEqualTo(aProductUITableId);

		queryBean.setSortProperty(IProductUITableColumnDAO.SortIndex);

		return queryProductUITableColumns(queryBean);
	}

	@Override
	protected ProductUITableColumnIconBean[] doGetProductUITableColumnIcons(long aProductUITableColumnId)
			throws Exception {

		ProductUITableColumnIconDAOQueryBean queryBean = new ProductUITableColumnIconDAOQueryBean();

		queryBean.createCriteria().andColumnIdEqualTo(aProductUITableColumnId);

		return ProductUITableColumnIconBean.toArray(this.productUITableColumnIconDao.query(queryBean));
	}

	@Override
	protected void doSetProductUITableColumnIcons(long aProductUITableColumnId,
			ProductUITableColumnIconBean[] aProductUITableColumnIcons) throws Exception {

		ProductUITableColumnIconDAOQueryBean queryBean = new ProductUITableColumnIconDAOQueryBean();

		queryBean.createCriteria().andColumnIdEqualTo(aProductUITableColumnId);

		ProductUITableColumnIcon[] columnIcons = new ProductUITableColumnIcon[aProductUITableColumnIcons.length];

		for (int i = 0; i < columnIcons.length; i++) {
			columnIcons[i] = aProductUITableColumnIcons[i].convertToProductUITableColumnIcon();

			columnIcons[i].setColumnId(aProductUITableColumnId);

		}

		this.productUITableColumnIconDao.synchronize(columnIcons, queryBean);

		this.productUITableDao.update(this.productUITableDao
				.findById(this.productUITableColumnDao.findById(aProductUITableColumnId).getTableId()));

	}

	@Override
	protected void doAddNewProductUIList(ProductUIListBean aProductUIList) throws Exception {

		this.productUIListDao.insert(aProductUIList.convertToProductUIList());

	}

	@Override
	protected void doModifyProductUIList(ProductUIListBean aProductUIList) throws Exception {

		this.productUIListDao.update(aProductUIList.convertToProductUIList());

	}

	@Override
	protected ProductUIListBean doGetProductUIListById(long aProductUIListId) throws Exception {

		ProductUIList productUIList = this.productUIListDao.findById(aProductUIListId);

		return productUIList != null ? new ProductUIListBean(productUIList) : null;
	}

	@Override
	protected void doDeleteProductUILists(long[] aProductUIListIds) throws Exception {

		ProductUIListDAOQueryBean queryBean = new ProductUIListDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIListIds);

		this.productUIListDao.delete(queryBean);

	}

	@Override
	protected ProductUIListBean[] doQueryProductUILists(ProductUIListDAOQueryBean queryBean) throws Exception {

		return ProductUIListBean.toArray(this.productUIListDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIListCount(ProductUIListDAOQueryBean queryBean) throws Exception {

		return this.productUIListDao.queryCount(queryBean);
	}

	@Override
	protected void doSetProductUIListOptions(long aProductUIListId, ProductUIListOptionBean[] aProductUIListOptions)
			throws Exception {

		ProductUIListOptionDAOQueryBean queryBean = new ProductUIListOptionDAOQueryBean();

		queryBean.createCriteria().andListIdEqualTo(aProductUIListId);

		ProductUIListOption[] listOptions = new ProductUIListOption[aProductUIListOptions.length];

		for (int i = 0; i < listOptions.length; i++) {
			listOptions[i] = aProductUIListOptions[i].convertToProductUIListOption();
			listOptions[i].setListId(aProductUIListId);
			listOptions[i].setSortIndex(i);
		}

		this.productUIListOptionDao.synchronize(listOptions, queryBean);

		this.productUIListDao.update(this.productUIListDao.findById(aProductUIListId));

	}

	@Override
	protected ProductUIListOptionBean[] doGetProductUIListOptions(long aProductUIListId) throws Exception {

		ProductUIListOptionDAOQueryBean queryBean = new ProductUIListOptionDAOQueryBean();

		queryBean.createCriteria().andListIdEqualTo(aProductUIListId);

		queryBean.setSortProperty(IProductUIListOptionDAO.SortIndex);

		return ProductUIListOptionBean.toArray(this.productUIListOptionDao.query(queryBean));
	}

	@Override
	protected void doAddNewProductUITab(ProductUITabBean aProductUITab) throws Exception {

		aProductUITab.setLastModifyTime(new Date());
		this.productUITabDao.insert(aProductUITab.convertToProductUITab());

	}

	@Override
	protected void doModifyProductUITab(ProductUITabBean aProductUITab) throws Exception {
		aProductUITab.setLastModifyTime(new Date());
		this.productUITabDao.update(aProductUITab.convertToProductUITab());

	}

	@Override
	protected void doDeleteProductUITabs(long[] aProductUITabIds) throws Exception {

		ProductUITabDAOQueryBean queryBean = new ProductUITabDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITabIds);

		this.productUITabDao.delete(queryBean);

	}

	@Override
	protected ProductUITabBean doGetProductUITabById(long aProductUITabId) throws Exception {

		ProductUITab productUITab = this.productUITabDao.findById(aProductUITabId);

		return productUITab != null ? new ProductUITabBean(productUITab) : null;
	}

	@Override
	protected ProductUITabBean[] doQueryProductUITabs(ProductUITabDAOQueryBean queryBean) throws Exception {

		return ProductUITabBean.toArray(this.productUITabDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITabCount(ProductUITabDAOQueryBean queryBean) throws Exception {

		return this.productUITabDao.queryCount(queryBean);
	}

	@Override
	protected void doSetProductUITabItems(long aProductUITabId, ProductUITabItemBean[] aProductUITabItems)
			throws Exception {

		ProductUITabItem[] tabItems = new ProductUITabItem[aProductUITabItems.length];

		for (int i = 0; i < tabItems.length; i++) {
			tabItems[i] = aProductUITabItems[i].convertToProductUITabItem();
			tabItems[i].setTabId(aProductUITabId);
			tabItems[i].setSortIndex(i);
		}

		ProductUITabItemDAOQueryBean queryBean = new ProductUITabItemDAOQueryBean();

		queryBean.createCriteria().andTabIdEqualTo(aProductUITabId);

		this.productUITabItemDao.synchronize(tabItems, queryBean);

		this.productUITabDao.update(this.productUITabDao.findById(aProductUITabId));

	}

	@Override
	protected ProductUITabItemBean[] doGetProductUITabItems(long aProductUITabId) throws Exception {

		ProductUITabItemDAOQueryBean queryBean = new ProductUITabItemDAOQueryBean();

		queryBean.createCriteria().andTabIdEqualTo(aProductUITabId);

		queryBean.setSortProperty(IProductUITabItemDAO.SortIndex);

		return ProductUITabItemBean.toArray(this.productUITabItemDao.query(queryBean));
	}

	@Override
	protected void doAddNewProductUITree(ProductUITreeBean aProductUITree) throws Exception {

		this.productUITreeDao.insert(aProductUITree.convertToProductUITree());

	}

	@Override
	protected void doModifyProductUITree(ProductUITreeBean aProductUITree) throws Exception {

		this.productUITreeDao.update(aProductUITree.convertToProductUITree());

	}

	@Override
	protected void doDeleteProductUITrees(long[] aProductUITreeIds) throws Exception {

		ProductUITreeDAOQueryBean queryBean = new ProductUITreeDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITreeIds);

		this.productUITreeDao.delete(queryBean);

	}

	@Override
	protected ProductUITreeBean doGetProductUITreeById(long aProductUITreeId) throws Exception {

		ProductUITree productUITree = this.productUITreeDao.findById(aProductUITreeId);

		return productUITree != null ? new ProductUITreeBean(productUITree) : null;
	}

	@Override
	protected ProductUITreeBean[] doQueryProductUITrees(ProductUITreeDAOQueryBean queryBean) throws Exception {

		return ProductUITreeBean.toArray(this.productUITreeDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITreeCount(ProductUITreeDAOQueryBean queryBean) throws Exception {

		return this.productUITreeDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUITreeNode(ProductUITreeNodeBean aProductUITreeNode) throws Exception {

		this.productUITreeNodeDao.insert(aProductUITreeNode.convertToProductUITreeNode());

		this.productUITreeDao.update(this.productUITreeDao.findById(aProductUITreeNode.getTreeId()));

	}

	@Override
	protected void doModifyProductUITreeNode(ProductUITreeNodeBean aProductUITreeNode) throws Exception {

		this.productUITreeNodeDao.update(aProductUITreeNode.convertToProductUITreeNode());

		this.productUITreeDao.update(this.productUITreeDao.findById(aProductUITreeNode.getTreeId()));

	}

	@Override
	protected void doDeleteProductUITreeNodes(long[] aProductUITreeNodeIds) throws Exception {

		ProductUITreeNodeDAOQueryBean queryBean = new ProductUITreeNodeDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITreeNodeIds);

		this.productUITreeDao.update(this.productUITreeDao
				.findById(this.productUITreeNodeDao.findById(aProductUITreeNodeIds[0]).getTreeId()));

		this.productUITreeNodeDao.delete(queryBean);

	}

	@Override
	protected ProductUITreeNodeBean doGetProductUITreeNodeById(long aProductUITreeNodeId) throws Exception {

		ProductUITreeNode treeNode = this.productUITreeNodeDao.findById(aProductUITreeNodeId);

		return treeNode != null ? new ProductUITreeNodeBean(treeNode) : null;
	}

	@Override
	protected ProductUITreeNodeBean[] doQueryProductUITreeNodes(ProductUITreeNodeDAOQueryBean queryBean)
			throws Exception {

		return ProductUITreeNodeBean.toArray(this.productUITreeNodeDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITreeNodeCount(ProductUITreeNodeDAOQueryBean queryBean) throws Exception {

		return this.productUITreeNodeDao.queryCount(queryBean);
	}

	@Override
	protected void doSetProductUITreeNodeBuilders(long aProductUITreeNodeId,
			ProductUITreeNodeBuilderBean[] aProductUITreeNodeBuilders) throws Exception {

		ProductUITreeNodeBuilder[] nodeBuilders = new ProductUITreeNodeBuilder[aProductUITreeNodeBuilders.length];

		for (int i = 0; i < nodeBuilders.length; i++) {
			nodeBuilders[i] = aProductUITreeNodeBuilders[i].convertToProductUITreeNodeBuilder();

			nodeBuilders[i].setNodeId(aProductUITreeNodeId);

			nodeBuilders[i].setSortIndex(i);

		}

		ProductUITreeNodeBuilderDAOQueryBean queryBean = new ProductUITreeNodeBuilderDAOQueryBean();

		queryBean.createCriteria().andNodeIdEqualTo(aProductUITreeNodeId);

		this.productUITreeNodeBuilderDao.synchronize(nodeBuilders, queryBean);

		this.productUITreeDao.update(
				this.productUITreeDao.findById(this.productUITreeNodeDao.findById(aProductUITreeNodeId).getTreeId()));

	}

	@Override
	protected ProductUITreeNodeBuilderBean[] doGetProductUITreeNodeBuilders(long aProductUITreeNodeId)
			throws Exception {

		ProductUITreeNodeBuilderDAOQueryBean queryBean = new ProductUITreeNodeBuilderDAOQueryBean();

		queryBean.createCriteria().andNodeIdEqualTo(aProductUITreeNodeId);

		queryBean.setSortProperty(IProductUITreeNodeBuilderDAO.SortIndex);

		return ProductUITreeNodeBuilderBean.toArray(this.productUITreeNodeBuilderDao.query(queryBean));
	}

	@Override
	protected ProductUITreeNodeBean[] doGetProductUITreeRootNodes(long aTreeId, long aParentNodeId) throws Exception {

		ProductUITreeRootNodeDAOQueryBean subQueryBean = new ProductUITreeRootNodeDAOQueryBean();

		subQueryBean.setDistinct(true);

		subQueryBean.addNodeIdSelectProperty();

		subQueryBean.createCriteria().andTreeIdEqualTo(aTreeId).andParentIdEqualTo(aParentNodeId);

		subQueryBean.setSortProperty(IProductUITreeRootNodeDAO.SortIndex);

		ProductUITreeNodeDAOQueryBean queryBean = new ProductUITreeNodeDAOQueryBean();

		queryBean.createCriteria().andTreeIdEqualTo(aTreeId).andIdIn(subQueryBean, productUITreeRootNodeDao);

		ProductUITreeRootNodeDAOQueryBean JionCriterion = new ProductUITreeRootNodeDAOQueryBean();

		JionCriterion.createCriteria().andTreeIdEqualTo(aTreeId).andParentIdEqualTo(aParentNodeId)
				.andNodeIdEqualToForeignKey(IProductUITreeNodeDAO.Id);

		queryBean.addJoin(IProductUITreeRootNodeDAO.EntityName, JionCriterion);

		queryBean.addAllSelectProperties();

		queryBean.addSelectProperty(IProductUITreeRootNodeDAO.SortIndex, "sortIndex");

		queryBean.setSortProperty(IProductUITreeRootNodeDAO.SortIndex);

		Map<String, Object>[] maps = this.productUITreeNodeDao.querySelective(queryBean);

		ProductUITreeNodeBean[] treeNodeBeans = new ProductUITreeNodeBean[maps.length];

		for (int i = 0; i < maps.length; i++) {
			Map<String, Object> map = maps[i];

			map.remove("sortIndex");

			ProductUITreeNodeBean nodeBean = new ProductUITreeNodeBean();

			// nodeBean.getBeanMap().putAll(map);

			treeNodeBeans[i] = nodeBean;

		}

		return treeNodeBeans;
	}

	@Override
	protected void doSetProductUITreeRootNodes(long aTreeId, long aParentNodeId,
			ProductUITreeNodeBean[] aProductUITreeNodes) throws Exception {

		ProductUITreeRootNodeDAOQueryBean queryBean = new ProductUITreeRootNodeDAOQueryBean();

		queryBean.createCriteria().andTreeIdEqualTo(aTreeId).andParentIdEqualTo(aParentNodeId);

		ProductUITreeRootNode[] rootNodes = new ProductUITreeRootNode[aProductUITreeNodes.length];

		for (int i = 0; i < rootNodes.length; i++) {
			rootNodes[i] = new ProductUITreeRootNode();
			rootNodes[i].setTreeId(aTreeId);
			rootNodes[i].setParentId(aParentNodeId);
			rootNodes[i].setNodeId(aProductUITreeNodes[i].getId());
			rootNodes[i].setSortIndex(i);
		}

		this.productUITreeRootNodeDao.synchronize(rootNodes, queryBean);

		this.productUITreeDao.update(this.productUITreeDao.findById(aTreeId));

	}

	@Override
	protected void doAddNewProductUIImage(ProductUIImageBean aProductUIImage) throws Exception {

		this.productUIImageDao.insert(aProductUIImage.convertToProductUIImage());

	}

	@Override
	protected void doModifyProductUIImage(ProductUIImageBean aProductUIImage) throws Exception {

		this.productUIImageDao.update(aProductUIImage.convertToProductUIImage());

	}

	@Override
	protected void doDeleteProductUIImages(long[] aProductUIImageIds) throws Exception {

		ProductUIImageDAOQueryBean queryBean = new ProductUIImageDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIImageIds);

		this.productUIImageDao.delete(queryBean);

	}

	@Override
	protected ProductUIImageBean doGetProductUIImageById(long aProductUIImageId) throws Exception {

		ProductUIImage productUIImage = this.productUIImageDao.findById(aProductUIImageId);

		return productUIImage != null ? new ProductUIImageBean(productUIImage) : null;
	}

	@Override
	protected ProductUIImageBean[] doQueryProductUIImages(ProductUIImageDAOQueryBean queryBean) throws Exception {

		return ProductUIImageBean.toArray(this.productUIImageDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIImageCount(ProductUIImageDAOQueryBean queryBean) throws Exception {

		return this.productUIImageDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIPageTemplate(ProductUIPageTemplateBean aProductUIPageTemplate) throws Exception {

		this.productUIPageTemplateDao.insert(aProductUIPageTemplate.convertToProductUIPageTemplate());

		syncPageTemplateParam(aProductUIPageTemplate.convertTo());

	}

	@Override
	protected void doModifyProductUIPageTemplate(ProductUIPageTemplateBean aProductUIPageTemplate) throws Exception {

		this.productUIPageTemplateDao.update(aProductUIPageTemplate.convertToProductUIPageTemplate());

		syncPageTemplateParam(aProductUIPageTemplate.convertTo());

	}

	@Override
	protected ProductUIPageTemplateBean doGetProductUIPageTemplateById(long aProductUIPageTemplateId) throws Exception {

		ProductUIPageTemplate pageTemplate = this.productUIPageTemplateDao.findById(aProductUIPageTemplateId);

		return pageTemplate != null ? new ProductUIPageTemplateBean(pageTemplate) : null;
	}

	@Override
	protected void doDeleteProductUIPageTemplates(long[] aProductUIPageTemplateIds) throws Exception {

		if (ArrayUtils.isEmpty(aProductUIPageTemplateIds)) {
			return;
		}

		ProductUIPageTemplateDAOQueryBean queryBean = new ProductUIPageTemplateDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIPageTemplateIds);

		this.productUIPageTemplateDao.delete(queryBean);

	}

	@Override
	protected ProductUIPageTemplateBean[] doQueryProductUIPageTemplates(ProductUIPageTemplateDAOQueryBean queryBean)
			throws Exception {

		return ProductUIPageTemplateBean.toArray(this.productUIPageTemplateDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIPageTemplateCount(ProductUIPageTemplateDAOQueryBean queryBean) throws Exception {

		return this.productUIPageTemplateDao.queryCount(queryBean);
	}

	@Override
	protected Date doGetProductUIFormLastModifyTime(long id) throws Exception {

		ProductUIFormDAOQueryBean queryBean = new ProductUIFormDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUIFormDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUIFormDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}
	}

	@Override
	protected Date doGetProductUITableLastModifyTime(long id) throws Exception {

		ProductUITableDAOQueryBean queryBean = new ProductUITableDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUITableDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUITableDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}
	}

	@Override
	protected Date doGetProductUITabLastModifyTime(long id) throws Exception {

		ProductUITabDAOQueryBean queryBean = new ProductUITabDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUITabDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUITabDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}

	}

	@Override
	protected Date doGetProductUIListLastModifyTime(long id) throws Exception {

		ProductUIListDAOQueryBean queryBean = new ProductUIListDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUIListDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUIListDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}

	}

	@Override
	protected Date doGetProductUIActionLastModifyTime(long id) throws Exception {

		ProductUIActionDAOQueryBean queryBean = new ProductUIActionDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUIActionDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUIActionDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}

	}

	@Override
	protected Date doGetProductUITreeLastModifyTime(long id) throws Exception {

		ProductUITreeDAOQueryBean queryBean = new ProductUITreeDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUITreeDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUITreeDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}

	}

	@Override
	protected Date doGetProductUIImageLastModifyTime(long id) throws Exception {

		ProductUIImageDAOQueryBean queryBean = new ProductUIImageDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUIImageDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUIImageDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}

	}

	@Override
	protected Date doGetProductUIActionGroupLastModifyTime(long id) throws Exception {

		ProductUIActionGroupDAOQueryBean queryBean = new ProductUIActionGroupDAOQueryBean();

		if (id != 0) {
			queryBean.createCriteria().andIdEqualTo(id);
		}

		queryBean.addMaxFunctionProperty(IProductUIActionGroupDAO.LastModifyTime, "lastModifyTime");

		Map<String, Object>[] maps = this.productUIActionGroupDao.querySelective(queryBean);

		if (ArrayUtils.isNotEmpty(maps)) {

			return (Date) maps[0].get("lastModifyTime");

		} else {

			return null;
		}

	}

	@Override
	protected void doAddNewProductUIListOption(ProductUIListOptionBean aProductUIListOption) throws Exception {

		ProductUIListOptionDAOQueryBean queryBean = new ProductUIListOptionDAOQueryBean();

		queryBean.createCriteria().andListIdEqualTo(aProductUIListOption.getListId());

		int count = this.productUIListOptionDao.queryCount(queryBean);

		aProductUIListOption.setSortIndex(count + 1);

		this.productUIListOptionDao.insert(aProductUIListOption.convertTo());

		ProductUIList uiList = this.productUIListDao.findById(aProductUIListOption.getListId());

		uiList.setLastModifyTime(new Date());

		this.productUIListDao.update(uiList);

	}

	@Override
	protected void doModifyProductUIListOption(ProductUIListOptionBean aProductUIListOption) throws Exception {

		ProductUIListOptionDAOQueryBean queryBean = new ProductUIListOptionDAOQueryBean();

		queryBean.setSortProperty(IProductUIListOptionDAO.SortIndex);

		queryBean.createCriteria().andListIdEqualTo(aProductUIListOption.getListId());

		ProductUIListOption[] listOptions = this.productUIListOptionDao.query(queryBean);

		if (ArrayUtils.isNotEmpty(listOptions)) {
			if (listOptions[aProductUIListOption.getSortIndex() - 1] != null
					&& listOptions[aProductUIListOption.getSortIndex() - 1].getId() != aProductUIListOption.getId()) {
				for (int i = 0; i < listOptions.length; i++) {
					if (listOptions[i].getId() == aProductUIListOption.getId()) {
						listOptions[aProductUIListOption.getSortIndex() - 1]
								.setSortIndex(listOptions[i].getSortIndex());
						this.productUIListOptionDao.update(listOptions[aProductUIListOption.getSortIndex() - 1]);
					}
				}
			}
		} else {
			aProductUIListOption.setSortIndex(1);
		}

		this.productUIListOptionDao.update(aProductUIListOption.convertTo());

		ProductUIList uiList = this.productUIListDao.findById(aProductUIListOption.getListId());

		uiList.setLastModifyTime(new Date());

		this.productUIListDao.update(uiList);

	}

	@Override
	protected void doDeleteProductUIListOptions(long[] aProductUIListOptionIds) throws Exception {

		ProductUIListOptionDAOQueryBean queryBean = new ProductUIListOptionDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIListOptionIds);

		queryBean.addListIdSelectProperty("listId");

		Map<String, Object>[] maps = this.productUIListOptionDao.querySelective(queryBean);

		this.productUIListOptionDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {

			Map<String, Object> map = maps[i];

			ProductUIList uiList = new ProductUIList();

			uiList.setId(MapUtils.getLongValue(map, "listId"));

			uiList.setLastModifyTime(new Date());

			this.productUIListDao.update(uiList);

			queryBean.clear();

			queryBean.setSortProperty(IProductUIListOptionDAO.SortIndex);

			queryBean.createCriteria().andListIdEqualTo(MapUtils.getLongValue(map, "listId"));

			ProductUIListOption[] listOptions = this.productUIListOptionDao.query(queryBean);

			for (int j = 0; j < listOptions.length; j++) {
				listOptions[j].setSortIndex(j + 1);
			}

			this.productUIListOptionDao.batchUpdate(listOptions);

		}

	}

	@Override
	protected ProductUIListOptionBean doGetProductUIListOptionById(long aProductUIListOptionId) throws Exception {

		ProductUIListOption listOption = this.productUIListOptionDao.findById(aProductUIListOptionId);

		return listOption != null ? new ProductUIListOptionBean(listOption) : null;
	}

	@Override
	protected ProductUIListOptionBean[] doQueryProductUIListOptions(ProductUIListOptionDAOQueryBean queryBean)
			throws Exception {
		return ProductUIListOptionBean.toArray(this.productUIListOptionDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIListOptionCount(ProductUIListOptionDAOQueryBean queryBean) throws Exception {
		return this.productUIListOptionDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUITableColumnIcon(ProductUITableColumnIconBean aProductUITableColumnIcon)
			throws Exception {

		this.productUITableColumnIconDao.insert(aProductUITableColumnIcon.convertTo());

	}

	@Override
	protected void doModifyProductUITableColumnIcon(ProductUITableColumnIconBean aProductUITableColumnIcon)
			throws Exception {

		this.productUITableColumnIconDao.update(aProductUITableColumnIcon.convertTo());

	}

	@Override
	protected void doDeleteProductUITableColumnIcons(long[] aProductUITableColumnIconIds) throws Exception {

		ProductUITableColumnIconDAOQueryBean queryBean = new ProductUITableColumnIconDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITableColumnIconIds);

		this.productUITableColumnIconDao.delete(queryBean);

	}

	@Override
	protected ProductUITableColumnIconBean doGetProductUITableColumnIconById(long aProductUITableColumnIconId)
			throws Exception {

		ProductUITableColumnIcon columnIcon = this.productUITableColumnIconDao.findById(aProductUITableColumnIconId);

		return columnIcon != null ? new ProductUITableColumnIconBean(columnIcon) : null;
	}

	@Override
	protected ProductUITableColumnIconBean[] doQueryProductUITableColumnIcons(
			ProductUITableColumnIconDAOQueryBean queryBean) throws Exception {
		return ProductUITableColumnIconBean.toArray(this.productUITableColumnIconDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITableColumnIconCount(ProductUITableColumnIconDAOQueryBean queryBean)
			throws Exception {
		return this.productUITableColumnIconDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUITabItem(ProductUITabItemBean aProductUITabItem) throws Exception {

		ProductUITabItemDAOQueryBean queryBean = new ProductUITabItemDAOQueryBean();

		queryBean.createCriteria().andTabIdEqualTo(aProductUITabItem.getTabId());

		int count = this.productUITabItemDao.queryCount(queryBean);

		aProductUITabItem.setSortIndex(count + 1);

		this.productUITabItemDao.insert(aProductUITabItem.convertTo());

		ProductUITab productUITab = this.productUITabDao.findById(aProductUITabItem.getTabId());

		productUITab.setLastModifyTime(new Date());

		this.productUITabDao.update(productUITab);

	}

	@Override
	protected void doModifyProductUITabItem(ProductUITabItemBean aProductUITabItem) throws Exception {

		ProductUITabItemDAOQueryBean queryBean = new ProductUITabItemDAOQueryBean();

		queryBean.setSortProperty(IProductUITabItemDAO.SortIndex);

		queryBean.createCriteria().andTabIdEqualTo(aProductUITabItem.getTabId());

		ProductUITabItem[] tabItems = this.productUITabItemDao.query(queryBean);

		if (tabItems[aProductUITabItem.getSortIndex() - 1] != null
				&& tabItems[aProductUITabItem.getSortIndex() - 1].getId() != aProductUITabItem.getId()) {
			for (int i = 0; i < tabItems.length; i++) {
				if (tabItems[i].getId() == aProductUITabItem.getId()) {
					tabItems[aProductUITabItem.getSortIndex() - 1].setSortIndex(tabItems[i].getSortIndex());
					this.productUITabItemDao.update(tabItems[aProductUITabItem.getSortIndex() - 1]);
				}
			}
		}

		this.productUITabItemDao.update(aProductUITabItem.convertTo());

		ProductUITab uiTab = this.productUITabDao.findById(aProductUITabItem.getTabId());

		uiTab.setLastModifyTime(new Date());

		this.productUITabDao.update(uiTab);

	}

	@Override
	protected void doDeleteProductUITabItems(long[] aProductUITabItemIds) throws Exception {

		ProductUITabItemDAOQueryBean queryBean = new ProductUITabItemDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITabItemIds);

		queryBean.addTabIdSelectProperty("tabId");

		Map<String, Object>[] maps = this.productUITabItemDao.querySelective(queryBean);

		this.productUITabItemDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {

			Map<String, Object> map = maps[i];

			ProductUITab uiTab = new ProductUITab();

			uiTab.setId(MapUtils.getLongValue(map, "tabId"));

			uiTab.setLastModifyTime(new Date());

			this.productUITabDao.update(uiTab);

			queryBean.clear();

			queryBean.setSortProperty(IProductUITabItemDAO.SortIndex);

			queryBean.createCriteria().andTabIdEqualTo(MapUtils.getLongValue(map, "tabId"));

			ProductUITabItem[] tabItems = this.productUITabItemDao.query(queryBean);

			for (int j = 0; j < tabItems.length; j++) {
				tabItems[j].setSortIndex(j + 1);
			}

			this.productUITabItemDao.batchUpdate(tabItems);

		}

	}

	@Override
	protected ProductUITabItemBean doGetProductUITabItemById(long aProductUITabItemId) throws Exception {

		ProductUITabItem tabItem = this.productUITabItemDao.findById(aProductUITabItemId);

		return tabItem != null ? new ProductUITabItemBean(tabItem) : null;
	}

	@Override
	protected ProductUITabItemBean[] doQueryProductUITabItems(ProductUITabItemDAOQueryBean queryBean) throws Exception {
		return ProductUITabItemBean.toArray(this.productUITabItemDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITabItemCount(ProductUITabItemDAOQueryBean queryBean) throws Exception {
		return this.productUITabItemDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUITreeNodeBuilder(ProductUITreeNodeBuilderBean aProductUITreeNodeBuilder)
			throws Exception {

		ProductUITreeNodeBuilderDAOQueryBean queryBean = new ProductUITreeNodeBuilderDAOQueryBean();

		queryBean.createCriteria().andNodeIdEqualTo(aProductUITreeNodeBuilder.getNodeId());

		int count = this.productUITreeNodeBuilderDao.queryCount(queryBean);

		aProductUITreeNodeBuilder.setSortIndex(count + 1);

		this.productUITreeNodeBuilderDao.insert(aProductUITreeNodeBuilder.convertTo());

	}

	@Override
	protected void doModifyProductUITreeNodeBuilder(ProductUITreeNodeBuilderBean aProductUITreeNodeBuilder)
			throws Exception {

		ProductUITreeNodeBuilderDAOQueryBean queryBean = new ProductUITreeNodeBuilderDAOQueryBean();

		queryBean.setSortProperty(IProductUITreeNodeBuilderDAO.SortIndex);

		queryBean.createCriteria().andNodeIdEqualTo(aProductUITreeNodeBuilder.getNodeId());

		ProductUITreeNodeBuilder[] builders = this.productUITreeNodeBuilderDao.query(queryBean);

		if (builders[aProductUITreeNodeBuilder.getSortIndex() - 1] != null
				&& builders[aProductUITreeNodeBuilder.getSortIndex() - 1].getId() != aProductUITreeNodeBuilder
						.getId()) {
			for (int i = 0; i < builders.length; i++) {
				if (builders[i].getId() == aProductUITreeNodeBuilder.getId()) {
					builders[aProductUITreeNodeBuilder.getSortIndex() - 1].setSortIndex(builders[i].getSortIndex());
					this.productUITreeNodeBuilderDao.update(builders[aProductUITreeNodeBuilder.getSortIndex() - 1]);
				}
			}
		}

		this.productUITreeNodeBuilderDao.update(aProductUITreeNodeBuilder.convertToProductUITreeNodeBuilder());

		// this.productUITreeDao.update(this.productUITreeDao.findById(aProductUITreeNodeBuilder.get));

	}

	@Override
	protected void doDeleteProductUITreeNodeBuilders(long[] aProductUITreeNodeBuilderIds) throws Exception {

		ProductUITreeNodeBuilderDAOQueryBean queryBean = new ProductUITreeNodeBuilderDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUITreeNodeBuilderIds);

		queryBean.addNodeIdSelectProperty("nodeId");

		Map<String, Object>[] maps = this.productUITreeNodeBuilderDao.querySelective(queryBean);

		this.productUITreeNodeBuilderDao.delete(queryBean);

		for (int i = 0; i < maps.length; i++) {

			Map<String, Object> map = maps[i];

			ProductUITreeNode uiTab = new ProductUITreeNode();

			uiTab.setId(MapUtils.getLongValue(map, "nodeId"));

			uiTab.setLastModifyTime(new Date());

			this.productUITreeNodeDao.update(uiTab);

			queryBean.clear();

			queryBean.setSortProperty(IProductUITreeNodeBuilderDAO.SortIndex);

			queryBean.createCriteria().andNodeIdEqualTo(MapUtils.getLongValue(map, "nodeId"));

			ProductUITreeNodeBuilder[] builders = this.productUITreeNodeBuilderDao.query(queryBean);

			for (int j = 0; j < builders.length; j++) {
				builders[j].setSortIndex(j + 1);
			}

			this.productUITreeNodeBuilderDao.batchUpdate(builders);

		}

	}

	@Override
	protected ProductUITreeNodeBuilderBean doGetProductUITreeNodeBuilderById(long aProductUITreeNodeBuilderId)
			throws Exception {

		ProductUITreeNodeBuilder nodeBuilder = this.productUITreeNodeBuilderDao.findById(aProductUITreeNodeBuilderId);

		return nodeBuilder != null ? new ProductUITreeNodeBuilderBean(nodeBuilder) : null;
	}

	@Override
	protected ProductUITreeNodeBuilderBean[] doQueryProductUITreeNodeBuilders(
			ProductUITreeNodeBuilderDAOQueryBean queryBean) throws Exception {

		return ProductUITreeNodeBuilderBean.toArray(this.productUITreeNodeBuilderDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUITreeNodeBuilderCount(ProductUITreeNodeBuilderDAOQueryBean queryBean)
			throws Exception {
		return this.productUITreeNodeBuilderDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIPageTemplateParam(ProductUIPageTemplateParamBean aProductUIPageTemplateParam)
			throws Exception {
		aProductUIPageTemplateParam.setLastModifyTime(new Date());
		this.productUIPageTemplateParamDao.insert(aProductUIPageTemplateParam.convertTo());
	}

	@Override
	protected void doModifyProductUIPageTemplateParam(ProductUIPageTemplateParamBean aProductUIPageTemplateParam)
			throws Exception {

		aProductUIPageTemplateParam.setLastModifyTime(new Date());
		this.productUIPageTemplateParamDao.update(aProductUIPageTemplateParam.convertTo());

	}

	@Override
	protected void doDeleteProductUIPageTemplateParams(long[] aProductUIPageTemplateParamIds) throws Exception {
		if (ArrayUtils.isEmpty(aProductUIPageTemplateParamIds)) {
			return;
		}
		ProductUIPageTemplateParamDAOQueryBean queryBean = new ProductUIPageTemplateParamDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIPageTemplateParamIds);

		this.productUIPageTemplateParamDao.delete(queryBean);
	}

	@Override
	protected ProductUIPageTemplateParamBean doGetProductUIPageTemplateParamById(long aProductUIPageTemplateParamId)
			throws Exception {

		ProductUIPageTemplateParam pageTemplateParam = this.productUIPageTemplateParamDao
				.findById(aProductUIPageTemplateParamId);

		return pageTemplateParam != null ? new ProductUIPageTemplateParamBean(pageTemplateParam) : null;
	}

	@Override
	protected ProductUIPageTemplateParamBean[] doQueryProductUIPageTemplateParams(
			ProductUIPageTemplateParamDAOQueryBean queryBean) throws Exception {
		return ProductUIPageTemplateParamBean.toArray(this.productUIPageTemplateParamDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIPageTemplateParamCount(ProductUIPageTemplateParamDAOQueryBean queryBean)
			throws Exception {
		return this.productUIPageTemplateParamDao.queryCount(queryBean);
	}

	protected void syncPageTemplateParam(ProductUIPageTemplate pageTemplate) throws Exception {

		ProductUIPageTemplateParamDAOQueryBean queryBean = new ProductUIPageTemplateParamDAOQueryBean();
		queryBean.createCriteria().andPageTemplateIdEqualTo(pageTemplate.getId());

		if (StringUtils.isEmpty(pageTemplate.getTemplateContent())) {

			this.productUIPageTemplateParamDao.delete(queryBean);
		} else {

			String content = new String(Base64.decodeBase64(pageTemplate.getTemplateContent()), "UTF-8");

			String[] requireParamCodes = StringUtils.substringsBetween(content, "${page[\"", "\"]}");

			String[] noRequireParamCodes = StringUtils.substringsBetween(content, "$!{page[\"", "\"]}");

			if (noRequireParamCodes == null) {
				noRequireParamCodes = ArrayUtils.EMPTY_STRING_ARRAY;
			}

			if (requireParamCodes == null) {
				requireParamCodes = ArrayUtils.EMPTY_STRING_ARRAY;
			}

			String[] paramCodes = new String[requireParamCodes.length + noRequireParamCodes.length];

			System.arraycopy(requireParamCodes, 0, paramCodes, 0, requireParamCodes.length);

			System.arraycopy(noRequireParamCodes, 0, paramCodes, requireParamCodes.length, noRequireParamCodes.length);

			ProductUIPageTemplateParam[] params = this.productUIPageTemplateParamDao.query(queryBean);

			Map<String, ProductUIPageTemplateParam> map = new HashMap<String, ProductUIPageTemplateParam>();

			for (int i = 0; i < params.length; i++) {
				map.put(params[i].getParamCode(), params[i]);
				if (ArrayUtils.contains(paramCodes, params[i].getParamCode()) == false) {
					this.productUIPageTemplateParamDao.delete(params[i].getId());
					map.remove(params[i].getParamCode());
				}
			}

			List<ProductUIPageTemplateParam> batchInsertList = new ArrayList<>();

			List<String> paramCodeList = new ArrayList<>();

			for (int i = 0; paramCodes != null && i < paramCodes.length; i++) {

				if (paramCodeList.contains(paramCodes[i])) {
					continue;
				}

				paramCodeList.add(paramCodes[i]);

				if (map.containsKey(paramCodes[i]) == false) {
					ProductUIPageTemplateParam param = new ProductUIPageTemplateParam();
					param.setPageTemplateId(pageTemplate.getId());
					param.setParamCode(paramCodes[i]);
					batchInsertList.add(param);
				}
			}
			if (batchInsertList.isEmpty() == false) {
				this.productUIPageTemplateParamDao
						.batchInsert(batchInsertList.toArray(new ProductUIPageTemplateParam[batchInsertList.size()]));
			}
		}
	}

	@Override
	protected void doAddNewProductUIPage(ProductUIPageBean aProductUIPage) throws Exception {

		this.productUIPageDao.insert(aProductUIPage.convertTo());

		ProductUIPageTemplateParamDAOQueryBean queryBean = new ProductUIPageTemplateParamDAOQueryBean();

		queryBean.createCriteria().andPageTemplateIdEqualTo(aProductUIPage.getPageTemplateId());

		ProductUIPageTemplateParam[] templateParams = this.productUIPageTemplateParamDao.query(queryBean);

		ProductUIPageParam[] pageParams = new ProductUIPageParam[templateParams.length];

		for (int i = 0; i < templateParams.length; i++) {
			pageParams[i] = new ProductUIPageParam();
			pageParams[i].setPageId(aProductUIPage.getId());
			pageParams[i].setPageParamId(templateParams[i].getId());
		}

		if (ArrayUtils.isNotEmpty(pageParams)) {
			this.productUIPageParamDao.batchInsert(pageParams);
		}
	}

	@Override
	protected void doModifyProductUIPage(ProductUIPageBean aProductUIPage) throws Exception {

		this.productUIPageDao.update(aProductUIPage.convertTo());

		ProductUIPageTemplateParamDAOQueryBean queryBean = new ProductUIPageTemplateParamDAOQueryBean();

		queryBean.createCriteria().andPageTemplateIdEqualTo(aProductUIPage.getPageTemplateId());

		ProductUIPageTemplateParam[] templateParams = this.productUIPageTemplateParamDao.query(queryBean);

		Map<Long, ProductUIPageTemplateParam> templateParamMap = new HashMap<>();

		for (int i = 0; i < templateParams.length; i++) {
			templateParamMap.put(templateParams[i].getId(), templateParams[i]);
		}

		ProductUIPageParamDAOQueryBean paramQueryBean = new ProductUIPageParamDAOQueryBean();

		paramQueryBean.createCriteria().andPageIdEqualTo(aProductUIPage.getId());

		ProductUIPageParam[] pageParams = this.productUIPageParamDao.query(paramQueryBean);

		Map<Long, ProductUIPageParam> pageParamMap = new HashMap<>();

		List<Long> deleteList = new ArrayList<>();

		for (int i = 0; i < pageParams.length; i++) {
			pageParamMap.put(pageParams[i].getPageParamId(), pageParams[i]);
			if (templateParamMap.containsKey(pageParams[i].getPageParamId()) == false) {
				deleteList.add(pageParams[i].getId());
			}
		}

		List<ProductUIPageParam> addList = new ArrayList<>();

		for (int i = 0; i < templateParams.length; i++) {
			if (pageParamMap.containsKey(templateParams[i].getId()) == false) {
				ProductUIPageParam pageParam = new ProductUIPageParam();
				pageParam.setPageId(aProductUIPage.getId());
				pageParam.setPageParamId(templateParams[i].getId());
				addList.add(pageParam);
			}
		}

		if (deleteList.isEmpty() == false) {

			paramQueryBean.clear();

			paramQueryBean.createCriteria().andIdIn(deleteList);

			this.productUIPageParamDao.delete(paramQueryBean);
		}

		if (addList.isEmpty() == false) {
			this.productUIPageParamDao.batchInsert(addList.toArray(new ProductUIPageParam[addList.size()]));
		}

	}

	@Override
	protected void doDeleteProductUIPages(long[] aProductUIPageIds) throws Exception {

		if (ArrayUtils.isEmpty(aProductUIPageIds)) {
			return;
		}

		ProductUIPageDAOQueryBean queryBean = new ProductUIPageDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIPageIds);

		this.productUIPageDao.delete(queryBean);

	}

	@Override
	protected ProductUIPageBean doGetProductUIPageById(long aProductUIPageId) throws Exception {

		ProductUIPage page = this.productUIPageDao.findById(aProductUIPageId);

		return page != null ? new ProductUIPageBean(page) : null;
	}

	@Override
	protected ProductUIPageBean[] doQueryProductUIPages(ProductUIPageDAOQueryBean queryBean) throws Exception {

		return ProductUIPageBean.toArray(this.productUIPageDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIPageCount(ProductUIPageDAOQueryBean queryBean) throws Exception {
		return this.productUIPageDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductUIPageParam(ProductUIPageParamBean aProductUIPageParam) throws Exception {

		this.productUIPageParamDao.insert(aProductUIPageParam.convertTo());

	}

	@Override
	protected void doModifyProductUIPageParam(ProductUIPageParamBean aProductUIPageParam) throws Exception {

		this.productUIPageParamDao.update(aProductUIPageParam.convertTo());

	}

	@Override
	protected void doDeleteProductUIPageParams(long[] aProductUIPageParamIds) throws Exception {

		if (ArrayUtils.isEmpty(aProductUIPageParamIds)) {
			return;
		}

		ProductUIPageParamDAOQueryBean queryBean = new ProductUIPageParamDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductUIPageParamIds);

		this.productUIPageParamDao.delete(queryBean);

	}

	@Override
	protected ProductUIPageParamBean doGetProductUIPageParamById(long aProductUIPageParamId) throws Exception {

		ProductUIPageParam pageParam = this.productUIPageParamDao.findById(aProductUIPageParamId);

		return pageParam != null ? new ProductUIPageParamBean(pageParam) : null;
	}

	@Override
	protected ProductUIPageParamBean[] doQueryProductUIPageParams(ProductUIPageParamDAOQueryBean queryBean)
			throws Exception {
		return ProductUIPageParamBean.toArray(this.productUIPageParamDao.query(queryBean));
	}

	@Override
	protected int doQueryProductUIPageParamCount(ProductUIPageParamDAOQueryBean queryBean) throws Exception {
		return this.productUIPageParamDao.queryCount(queryBean);
	}
}
